package com.daisuxia.web.synchronization;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.daisuxia.back.dao.ILocalDataDao;
import com.daisuxia.constant.Constant;

import redis.clients.jedis.JedisCluster;

/**
 * 处理代扣数据
 * @author gaoyuhai
 *
 */
public class OperaWithDataThread implements Runnable {

	private static Logger loger = Logger.getLogger(OperaWithDataThread.class);
	private String withId;
	private ILocalDataDao localDataDao;

	public OperaWithDataThread(String withId,ILocalDataDao localDataDao,RedisUtil redisUtil) {
		this.withId = withId;
		this.localDataDao = localDataDao;
		this.redisUtil = redisUtil;
	}

	private RedisUtil redisUtil;

	public OperaWithDataThread() {

	}

	@Override
	public void run() {
		if (StringUtils.isNotBlank(withId)) {
			String result = redisUtil.jedisCluster.get(Constant.TYPE_WITHHOLD_ + withId);
			loger.error("sync-OperaWithDataThread:"+withId+"status"+result);
			String status =null;
			if(null!=result&&"true".equals(result)) 
				status = "1";
			else 
				status = "2";
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("status", status);
			map.put("ID", withId);
			this.localDataDao.updateWithHold(map);
			redisUtil.delRedisKey(Constant.TYPE_WITHHOLD_ + withId);
		}else{
			redisUtil.delRedisKey(Constant.TYPE_WITHHOLD_ + withId);
		}
	}

}
